<template>
  <div class='search'>
    <f-form ref='form' :action='api.bpd' :form-key='this.formItem.policyDrugId'>
      <f-form-item label='商品名称' extra='商品名称用于模糊匹配' placeholder='请填写商品名称' name='drugsName'  :required='true' :value.sync='formItem.drugsName'/>
      <f-form-item label='规格'  placeholder='请填写规格' name='drugsSpec'  :required='true' :value.sync='formItem.drugsSpec'/>
      <f-form-item label="商品类型" type='radio' name="drugType"  :required="true" :data='api.busCommon.drugType' :value.sync="formItem.drugType"/>
      <f-form-item label='部门结算价' v-if='formItem.drugType=="ZY"' type='number' :precision='3' data-type='number' name='deptPrice' :value='formItem.deptPrice' />
      <f-form-item label='部门结算标准' tooltip='格式用小数表示,示例值0.18' type='number' :precision='3' data-type='number' name='deptRate' :value='formItem.deptRate' v-if='formItem.drugType=="ZY"'/>
      <f-form-item label='部门结算公式' v-if='formItem.drugType=="ZY"' placeholder='请选择结算公式' name='deptSettleFormula' :readOnly='true' :required='true' :value.sync='formItem.deptSettleFormula' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openFormulaModal' />
        </a-tooltip>
      </f-form-item>
<!--      <f-form-item label='部门利润公式' v-if='formItem.drugType=="ZY"' placeholder='请选择利润公式' name='deptProfitAmountFormula' :readOnly='true' :required='true' :value.sync='formItem.deptProfitAmountFormula' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openDeptProfitAmountFormulaModal' />
        </a-tooltip>
      </f-form-item>-->
      
      <f-form-item label='底价方式' type='radio' name='floorPriceType' dataType='number' :data='api.busCommon.floorPriceType' :value.sync='formItem.floorPriceType' />
      <f-form-item label='备注' name='remark' :value='formItem.remark' />
    </f-form>
    <select-formula-modal ref='formulaModal' @onSelectChange='onSelectFormulaChange'></select-formula-modal>
    <select-hy-policy-drugs-modal ref='drugsModal' @drugsSelectChange='drugsSelectChange'></select-hy-policy-drugs-modal>
    <select-formula-modal ref='deptProfitAmountFormulaModal' @onSelectChange='onSelectDeptProfitFormulaChange'></select-formula-modal>
  </div>
</template>
<script>
import api from "../../../js/api"
import SelectFormulaModal from "../../../components/select_formula_modal"
import SelectHyPolicyDrugsModal from "@/views/module/haiying/components/select_hy_policy_drugs_modal"

export default {
  name: "drugsForm",
  props: {},
  data() {
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      params1: {
        formulaType: 3
      },
      params2: {
        formulaType: 6
      },
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        policyDrugId: "",
        deptPrice: "",
        deptRate: "",
        floorPriceType:2,
        remark: "",
        deptSettleFormula: ""
      }
    },
    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.policyDrugId) {
        let params = {
          policyDrugId: data.policyDrugId
        }
        this.refs["form"].getDetails(params, (data) => {
          this.formItem = data
          this.loaded = true
        })
        this.isAdd = false
      } else {
        this.loaded = true
      }
    },
    //商品选择框
    openDrugsModal() {
      this.$refs["drugsModal"].open(this.supplierId)
    },
    //商品选择回调
    drugsSelectChange(selectedRowKeys, selectedRows) {
      this.$refs["form"].getForm().setFieldsValue({ "drugsName": selectedRows[0].drugsName })
      this.formItem.drugsName = selectedRows[0].drugsName
      this.formItem.drugNo = selectedRowKeys[0]
      this.formItem.drugsSpec = selectedRows[0].drugsSpec
      this.formItem.producersName = selectedRows[0].producersName
      this.formItem.supplierName = selectedRows[0].supplierName
      this.formItem.drugJr = selectedRows[0].drugJr
      this.formItem.drugType = selectedRows[0].drugType
      this.selectDrug = selectedRows[0]
      this.$refs["form"].getForm().setFieldsValue({ "drugLotNo": "" })
      this.$forceUpdate()
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit({
        drugsName: this.formItem.drugsName,
        drugCode: this.formItem.drugNo,
        producersName: this.formItem.producersName,
        supplierName: this.formItem.supplierName,
        drugJr: this.formItem.drugJr,
        drugType: this.formItem.drugType,
        drugsSpec: this.formItem.drugsSpec
      }, callback)
    },
    /**
     * 选择公式
     */
    openFormulaModal() {
      this.$refs["formulaModal"].open({
        formulaType: 4
      })
    },
    /**
     * 选择部门利润公式
     */
    openDeptProfitAmountFormulaModal() {
      this.$refs["deptProfitAmountFormulaModal"].open({
        formulaType: 6
      })
    },
    /**
     * 部门利润
     */
    onSelectDeptProfitFormulaChange(selectedRowKeys, selectedRows){
      this.$refs.form.getForm().setFieldsValue({ "deptProfitAmountFormula": selectedRows[0].formulaContent })
    },
    /**
     * 公式选择回调
     */
    onSelectFormulaChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "deptSettleFormula": selectedRows[0].formulaContent })
      this.formItem.deptSettleFormula = selectedRows[0].formulaContent
    }
  },
  created() {
  },
  components: { SelectHyPolicyDrugsModal, SelectFormulaModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
